//
//  TodayLuckyBagViewController.m
//  一点互助
//
//  Created by rimi on 16/8/24.
//  Copyright © 2016年 zhangboqiu. All rights reserved.
//

#import "TodayLuckyBagViewController.h"
#import "UIViewController+NavagitionBar.h"
#import "URLDefine.h"
#import "ResponseManager.h"
#import "FBProgressView.h"
#import "PieView.h"

@interface TodayLuckyBagViewController ()
@property (weak, nonatomic) IBOutlet UIView *view1;
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (weak, nonatomic) IBOutlet UILabel *XELabel;
@property (weak, nonatomic) IBOutlet UILabel *DELabel;
@property (weak, nonatomic) IBOutlet UILabel *countLabel;
@property (assign, nonatomic) NSInteger XE;
@property (assign, nonatomic) NSInteger DE;
@property (strong, nonatomic) NSString *str;
@property (strong, nonatomic) NSDictionary *dataSource;
@property (strong, nonatomic) PieView *piewView;
@end

@implementation TodayLuckyBagViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupBackItem];
    self.title = @"今日福包动态";
    [self getNetwork];
    // Do any additional setup after loading the view, typically from a nib.
    }

-(void)viewWillAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self.tabBarController.tabBar setHidden:YES];
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    [self.tabBarController.tabBar setHidden:NO];
}

-(void)getNetwork{
    __weak typeof(self) myself = self;
    [FBProgressView showWithMessage:nil];
    [ResponseManager startGetRequestWithURLString:kTodayLuckyBagDTURL parameters:nil completionHandler:^(FBResponse *response) {
        if (response.success) {
            [FBProgressView hide];
            PLLOG(@"%@",response.resultValue);
            self.dataSource = [response.resultValue copy];
            PieModel *model1 = [[PieModel alloc] initWithVaule:[self.dataSource[@"de"] integerValue] color:[UIColor redColor]];
            PieModel *model2 = [[PieModel alloc] initWithVaule:[self.dataSource[@"xe"] integerValue] color:[UIColor greenColor]];
            myself.piewView = [[PieView alloc] initWithFrame:myself.view1.frame pieModels:@[model1, model2] offset:0];
            myself.piewView.frame = self.view1.bounds;
            myself.piewView.bounds = CGRectMake(CGRectGetWidth(myself.view1.frame)/4, 0, CGRectGetWidth(myself.view1.bounds)/2, 150);
            [myself.view1 addSubview:self.piewView];
            [myself refreshView];
        }else{
            [self addAlertControllerWithTitle:@"提示" message:response.resultDesc actionNum:2 style:UIAlertControllerStyleAlert handler:^(UIAlertAction *action) {
                [myself getNetwork];
            }];
        }
    }];
}
-(void)refreshView{
    self.XELabel.text = [NSString stringWithFormat:@"%@",self.dataSource[@"xe"]];
    self.DELabel.text = [NSString stringWithFormat:@"%@",self.dataSource[@"de"]];
    self.textView.text = self.dataSource[@"desc"];
    self.countLabel.text = [NSString stringWithFormat:@"%@",self.dataSource[@"today"]];
}
-(NSDictionary *)dataSource{
    if (!_dataSource) {
        _dataSource = [NSDictionary dictionary];
    }
    return _dataSource;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
